<!DOCTYPE html>
<html><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Simple Tables</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->


    <link rel="stylesheet" href="/css/dialog.css">
    <!-- Font Awesome -->
    <script type="text/javascript" src="libs/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery.dialog.js"></script>

    <style>
        div{
            font-size:18px;
        }
        td{
            padding-left: 10px;
            padding-right: 10px;
        }


    </style>
</head>
<body class="skin-blue sidebar-mini">
<div class="wrapper">
   选择电影 <select style="width: 120px;" id="select_dianying">

    </select>
  <input type="button" value="查询" onclick="search()">

  <div>
      输入日期：<input type="text" id="input_add_date">
      观看指数：<input type="text" id="input_add_look">
      百度指数：<input type="text" id="input_add_baidu">
      微信信指数：<input type="text" id="input_add_weixin">
      上映天数：<input type="text" id="input_add_day">
      <input type="button" onclick="AddZhishu()" value="添加">
  </div>
</div>
<br><br>
<di>
    <table>
        <thead>
            <tr>
                <td>
                    上映第几天
                </td>
                <td>
                    观看指数
                </td>
                <td>
                    百度指数
                </td>
                <td>
                    微信信指数
                </td>
                <td>
                    日期
                </td>
                <td>
                    操作
                </td>
            </tr>
        </thead>
        <tbody id="table_body">

        </tbody>
    </table>
</di>
</body>
<script>


    getAllMovie();
    var Now_Date=new Date();
    $('#input_add_date').val(Now_Date.getFullYear()+'-'+Now_Date.getMonth()+'-'+Now_Date.getDate())

    function  getAllMovie() {
        $.ajax({
            type: 'get',
            url: '/api/index/getallmovie',
            dataType: 'json',
            success: function(data){
                var videoList=data.result;
                if(videoList&& videoList.length>0){
                    $.each(videoList,function (index,item) {
                        //天聪数据
                        $('#select_dianying').append('<option value="'+item.baseid+'">'+item.name+'</option>');

                    });



                }
            }
        });
    }
    
    function search() {
        $.ajax({
            type: 'get',
            url: '/api/details/getzhishu?id=' + $('#select_dianying').val(),
            dataType: 'json',
            success: function (data) {

                if (data){
                    //
                    var _html='';
                    $.each(data.result,function (index,item) {
                        _html+='<tr>' +
                             '<td><input type="text" id="input_day_'+index+'" value="'+item.curDate+'"></td>'+
                            '<td><input type="text" id="input_look_'+index+'" value="'+item.lookNum+'"></td>'+
                            '<td><input type="text" id="input_baidu_'+index+'"  value="'+item.baiduNum+'"></td>'+
                            '<td><input type="text" id="input_weixin_'+index+'"  value="'+item.weixinNum+'"></td>'+
                            '<td><input type="text" id="input_date_'+index+'"  value="'+item.createDate+'"></td>'+
                            '<td><input type="button" value="修改" onclick="update(\''+index+'\',' +
                            '\''+item.id+'\')">' +
                            '<input type="button" value="删除" onclick="deletebyid(\''+item.id+'\')">' +
                            '</td>'+
                            '</tr>'
                    });
                    $('#table_body').html(_html)
                }

            }
        });
    }
    function update(index,id) {
        var _bd=$('#input_baidu_'+index).val();
        var _look=$('#input_look_'+index).val();
        var _weixin=$('#input_weixin_'+index).val();

        var _date=$('#input_date_'+index).val();
        var _day=$('#input_day_'+index).val();
        $.ajax({
            type: 'get',
            url:
            '/api/keybaseJava/upzhishu?id='+id +'&baiduNum='+_bd+'&lookNum='+_look+'&weixinNum='+_weixin+'&date='+_date
            +'&day='+_day,
            dataType: 'json',
            success: function (data) {

                if (data.code=='OperateOk'){
                    //
                    alert('操作成功')
                }else{
                    alert('操作失败')
                }

            }
        });
    }

    function deletebyid(id){

        $.ajax({
            type: 'get',
            url:
            '/api/keybaseJava/delzhishu?id='+id ,
            dataType: 'json',
            success: function (data) {

                if (data.code=='OperateOk'){
                    //
                    alert('操作成功');
                    search();
                }else{
                    alert('操作失败')
                }

            }
        });
    }
    
    function AddZhishu() {
        var _bd=$('#input_add_baidu').val();
        var _look=$('#input_add_look').val();
        var _weixin=$('#input_add_weixin').val();
        var _date=$('#input_add_date').val();
        var _day=$('#input_add_day').val();
        var baseid=$('#select_dianying').val();
        if (!baseid){
            alert('请选择电影');
            return;
        }
        $.ajax({
            type: 'post',
            url:
            '/api/keybaseJava/addzhishu?baiduNum='+_bd+'&lookNum='+_look+'&weixinNum='+_weixin+'&date='+_date
            +'&day='+_day+'&baseid='+baseid,
            dataType: 'json',
            success: function (data) {
                if (data.code=='OperateOk'){
                    //
                    alert('操作成功');
                    $('#input_add_baidu').val('');
                    $('#input_add_look').val('');
                    $('#input_add_weixin').val('');

                    $('#input_add_day').val('');
                    search();
                }else{
                    alert('操作失败')
                }

            }
        });
    }
</script>
</html>